home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 3 / Cream of the Crop 3.iso / utility / secdrv.zip / LOGIN.C < prev    next >
C/C++ Source or Header  |  1993-11-19  |  4KB  |  136 lines

  1. /* Secure Drive LOGIN V1.0 */
  2. /* Logs into encrypted disks */
  3.  
  4. #include "secdrv.h"
  5.  
  6. main(int argc,char *argv[])
  7. {
  8. unsigned drive,firstcyl,firsthead,maxtrack;
  9. unsigned maxhead,maxsector,secsize,i;
  10. unsigned safemode=FALSE;
  11. unsigned char buf[512],key[16],check[4];
  12. word16 expkey[52];
  13. unsigned serial[2];
  14.  
  15. if(argc==1) {
  16.     printf("\n\
  17. Secure Drive Login Version 1.0\n\
  18. This program sets parameters and loads passphrases for encrypted\
  19.  drives.\n\n\
  20. LOGIN /F                         to enter floppy disk passphrase\n\
  21. \n\
  22. LOGIN /C                         to erase keys and disable encryption\n\
  23. \n\
  24. LOGIN drive letter               to activate an encrypted hard drive\n\
  25. LOGIN D:    (example)\n\
  26. LOGIN D: /S                      to prevent accidental access to an\n\
  27.                  encrypted drive without logging in\n\
  28. \n\
  29. LOGIN drive cylinder head        to manually enter parameters for\n\
  30.                  a hard drive partition\n\
  31. LOGIN drive cylinder head /S     to prevent accidental access\n\
  32. LOGIN 0 100 1 (example)\n\
  33.       drives are numbered from zero\n\n");
  34.     exit(1); }
  35.  
  36. if(!(cryptdata=gettsradr())) {
  37.     printf("\nError: Secure Drive TSR not loaded.\n");
  38.     exit(1); }
  39.  
  40. if((*argv[1]=='/')&&(toupper(*(argv[1]+1))=='C')) {
  41.    cryptdata->hd.active=0;
  42.    for(i=0;i<104;i++) {
  43.        cryptdata->fkey[i]=0xaa;
  44.        cryptdata->hkey[i]=0xbb; }
  45.    for(i=0;i<4;i++)
  46.        cryptdata->fkeychk[i]=0x0ff;
  47.    printf("\nAll keys erased. System secured.\n");
  48.    exit(0); }
  49.  
  50. else if((*argv[1]=='/')&&(toupper(*(argv[1]+1))=='F')) {
  51.    printf("\nEnter floppy disk passphrase: ");
  52.    getkey(key,check,FALSE);
  53.    en_key_idea((word16 *) key,expkey);
  54.    memcpy(cryptdata->fkey,expkey,104);
  55.    memcpy(cryptdata->fkeychk,check,4);
  56.    cryptdata->fda.firstcyl=0;
  57.    cryptdata->fdb.firstcyl=0;
  58.    printf("\nFloppy disk encryption enabled.\n");
  59.    exit(0); }
  60.  
  61. else if(isalpha(*argv[1])) {
  62.    char drvltr=toupper(*argv[1]);
  63.    drive=255;
  64.    readptbl(0,0,0,drvltr,&drive,&firsthead,&firstcyl);
  65.    if(drive==255) {
  66.        printf("\nDrive not found.\n");
  67.        exit(1); }
  68.    if((*argv[2]=='/')&&(toupper(*(argv[2]+1))=='S'))
  69.        safemode=TRUE;
  70.    printf("\nDrive %c is physical hard drive %u, head %u,\
  71.  cylinder %u\n",drvltr,drive,firsthead,firstcyl); }
  72.  
  73. else {
  74.     i=sscanf(argv[1],"%u",&drive);
  75.     i=i&&sscanf(argv[2],"%u",&firstcyl);
  76.     i=i&&sscanf(argv[3],"%u",&firsthead);
  77.     if((*argv[4]=='/')&&(toupper(*(argv[4]+1))=='S'))
  78.     safemode=TRUE;
  79.     if(!i) {
  80.     printf("\nIncorrect drive, track, or head input.\n\
  81. Run without a command line for help.\n");
  82.     exit(1); }
  83.     }
  84.  
  85. drive+=0x80;
  86.  
  87. readsec(drive,firsthead,firstcyl,1,1,buf);
  88.  
  89. if((buf[510]!=0x55)||(buf[511]!=0xaa)) {
  90.     printf("\nThis is not a boot sector.\n");
  91.     exit(1); }
  92.  
  93. calcdiskparams(buf,&maxtrack,&maxhead,&maxsector,
  94.            &secsize,serial);
  95.  
  96. printf("\nThis disk has: %i tracks, %i sectors, %i heads, sector \
  97. size %i bytes\n",maxtrack+1,maxsector,maxhead,secsize);
  98.  
  99. if(memcmp("CRYP",buf+3,4)) {
  100.     printf("\nThis disk is not encrypted.\n");
  101.     exit(1); }
  102.  
  103. if(!safemode) {
  104.     printf("\nEnter hard disk passphrase: ");
  105.     getkey(key,check,FALSE);
  106.  
  107.     if(memcmp(check,buf+7,4)) {
  108.     printf("\nWrong passphrase.\n");
  109.     exit(1); }
  110.  
  111.     en_key_idea((word16 *)key,expkey);
  112.  
  113.     memcpy(cryptdata->hkey,expkey,104); }
  114.  
  115. cryptdata->hdnum=drive;
  116. cryptdata->hd.firstcyl=firstcyl;
  117. cryptdata->hd.firsthd=firsthead;
  118. cryptdata->hd.firstsec=1;
  119. cryptdata->hd.lastcyl=firstcyl+maxtrack;
  120. cryptdata->hd.maxsec=maxsector;
  121. cryptdata->hd.maxhd=maxhead;
  122. cryptdata->hd.secsize=secsize;
  123. cryptdata->hdnum=drive;
  124. if(!safemode) {
  125.     cryptdata->hd.serial[0]=serial[0];
  126.     cryptdata->hd.serial[1]=serial[1];
  127.     cryptdata->hd.active=1;
  128.     printf("\nHard disk encryption enabled.\n"); }
  129. else printf("\nHard disk set to safe mode.\n");
  130.  
  131. for(i=0;i<16;i++) key[i]='\0';
  132. for(i=0;i<52;i++) expkey[i]=0;
  133.  
  134. exit(0);
  135. }
  136.